//
//  CLAdsorbButtonViewController.m
//  Charles
//
//  Created by Leo on 2017/4/6.
//  Copyright © 2017年 charles. All rights reserved.
//

#import "CLAdsorbButtonViewController.h"
#import "CLAdsorbButton.h"
#import "CLFloatWindow.h"

@interface CLAdsorbButtonViewController ()<CLAdsorbButtonDelegate> {
    CLAdsorbButton *_button;
    CLFloatWindow *_window;
}

@end

@implementation CLAdsorbButtonViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"AdsorbButton";
    dispatch_async(dispatch_get_main_queue(), ^{
        [self setUpViews];
    });
}

- (void)setUpViews {
    
    // 悬浮按钮
    _button = [CLAdsorbButton buttonWithType:UIButtonTypeCustom];
    // 按钮图片伸缩充满整个按钮
    _button.imageView.contentMode = UIViewContentModeScaleToFill;
    _button.backgroundColor = [UIColor redColor];
    _button.frame = CGRectMake(0, 0, 40, 40);
    // 按钮点击事件
    [_button addTarget:self action:@selector(floatBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
    // 初始选中状态
    _button.selected = NO;
    // 禁止高亮
    _button.adjustsImageWhenHighlighted = NO;
    _button.rootView = self.view.superview;
    _button.delegate = self;
    _button.isAdsorb = NO;
    _button.imageView.alpha = 0.8;
    
    // 悬浮窗
    _window = [[CLFloatWindow alloc]init];
    _window.floatFrame = CGRectMake(SCREEN_WIDTH - 40, (SCREEN_HEIGHT - 40)/2, 40, 40);
    _window.windowLevel = UIWindowLevelAlert+1;
    _window.backgroundColor = [UIColor clearColor];
    _window.layer.cornerRadius = 40/2;
    _window.layer.masksToBounds = YES;
    _button.originFrame = CGRectMake(SCREEN_WIDTH - 40, (SCREEN_HEIGHT - 40)/2, 40, 40);
    // 将按钮添加到悬浮按钮上
    [_window addSubview:_button];
    //显示window
    [_window makeKeyAndVisible];
}

- (void)floatBtnClicked:(UIButton*)sender {
    NSLog(@"-----");
}

- (void)adsorbButtonClicked:(UIButton*)sender {
    NSLog(@"+++++");
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
